package com.abe.jmcl.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;

import com.abe.jmcl.R;
import com.abe.jmcl.entity.BaseMenuEntity;
import com.abeframe.core.libs.adapter.BaseXApapter;
import com.abeframe.core.libs.adapter.CommonData;
import com.abeframe.core.libs.adapter.autobase.ViewHolderUtils;
import com.abeframe.core.utils.ScreenUtils;

import java.util.List;

public class MenuCommonAdapter extends BaseXApapter {

    public static final String TYPE_MENU_FRAME = "TYPE_MENU_FRAME";
    public static final String TYPE_MENU_MODULE = "TYPE_MENU_MODULE";

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        CommonData temData = data.get(i);
        switch (temData.getType()) {
            case TYPE_MENU_MODULE:
            case TYPE_MENU_FRAME: {
                view = inflater
                        .inflate(R.layout.item_grid_menu_main,
                                viewGroup, false);

                int width = ScreenUtils.getScreenWidth();
                int length = (int) ((double) width / (double) 3);
                view.setLayoutParams(new AbsListView.LayoutParams(length, length));
                ViewHolderUtils.ViewHolder holder = vh.get(view);
                BaseMenuEntity entity = ((BaseMenuEntity) temData.getData());
                if (entity != null) {
                    holder.getTextView(R.id.item_name).setText(entity.getMenuName());
                    holder.getImageView(R.id.item_image).setBackgroundResource(entity.getBackground());
                }
            }
            break;
        }
        return view;
    }

    public MenuCommonAdapter(Context context, List<CommonData> data) {
        super(context, data);
    }
}
